#exec将一个代码字符串传递给python解释器以执行
# modname='math'
# string=exec("import "+modname)
# print(math.sqrt(16))  # 输出: 4.0  
# print(math.pi)  # 输出: 3.141592653589793
#__import__函数来导入
modname = 'math'  
math_module = __import__(modname)  
print(math_module.sqrt(16))  # 输出: 4.0
